package com.ym.controller.patient.self;

import com.github.pagehelper.PageInfo;
import com.ym.common.constant.Constants;
import com.ym.common.utils.page.PageDomain;
import com.ym.core.annotation.ApiSign;
import com.ym.core.annotation.Log;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.core.shiro.ShiroUtil;
import com.ym.medical.domain.vo.MyOrderInfoVo;
import com.ym.medical.domain.vo.MyOrderListVo;
import com.ym.medical.service.IInquiryOrderSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 我的订单
 *
 * @author: 李涛
 * @version: 2019年05月14日 19:38
 */
@Api(tags = "患者端-个人中心-我的订单")
@Validated
@RestController
@ApiSign
@RequestMapping(value = "patient/self/order", headers = Constants.Api.VERSION)
public class MyOrderController extends BaseController {

	@Autowired
	private IInquiryOrderSV inquiryOrderSV;

	@Log(dataBase = false, printBody = false)
	@ApiOperation("我的未支付订单个数查询")
	@GetMapping(value = "/unPay/num")
	public APIResponse<Integer> unPayNum() {
		Integer unPayNum = inquiryOrderSV.unPayNum(ShiroUtil.getLoginId());
		return successData(unPayNum);
	}

	@Log(dataBase = false, printBody = false)
	@ApiOperation("我的订单列表查询")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "status", value = "状态值.0.全部1待付款2已结束3已退款", required = false, paramType = "query")
	})
	@GetMapping(value = "/list")
	public APIResponse<PageInfo<MyOrderListVo>> list(
			@RequestParam(defaultValue = "0") Long status
	) {
		PageDomain.startPage();
		List<MyOrderListVo> myOrderList = inquiryOrderSV.listMyOrdersPatient(ShiroUtil.getLoginId(), status);
		return successPage(myOrderList);
	}


	@Log(dataBase = false, printBody = false)
	@ApiOperation("我的订单详情查看")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "orderId", value = "订单ID", required = true, paramType = "query")
	})
	@GetMapping(value = "/info")
	public APIResponse<MyOrderInfoVo> info(
			@RequestParam Long orderId
	) {
		MyOrderInfoVo myOrderInfoVo = inquiryOrderSV.infoMyOrdersPatient(orderId);
		return successData(myOrderInfoVo);
	}


}
